<?php

/**
 * BonSortie filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseBonSortieFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'reference'               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'reference_bon_livraison' => new sfWidgetFormFilterInput(),
      'date_creation'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'date_validite'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'client_id'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Client'), 'add_empty' => true)),
      'departement_source_id'   => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('DepartementSource'), 'add_empty' => true)),
      'facture_id'              => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('FactureClient'), 'add_empty' => true)),
      'bon_livraison_client_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('BonLivraisonClient'), 'add_empty' => true)),
      'magasinie_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Employe'), 'add_empty' => true)),
      'observation'             => new sfWidgetFormFilterInput(),
      'confirme'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'valider'                 => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'livre'                   => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'cloture'                 => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'foire_id'                => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Foire'), 'add_empty' => true)),
      'created_at'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'deleted_at'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'm_stock_article_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle')),
      'stock_articles_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle')),
    ));

    $this->setValidators(array(
      'reference'               => new sfValidatorPass(array('required' => false)),
      'reference_bon_livraison' => new sfValidatorPass(array('required' => false)),
      'date_creation'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'date_validite'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'client_id'               => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Client'), 'column' => 'id')),
      'departement_source_id'   => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('DepartementSource'), 'column' => 'id')),
      'facture_id'              => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('FactureClient'), 'column' => 'id')),
      'bon_livraison_client_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('BonLivraisonClient'), 'column' => 'id')),
      'magasinie_id'            => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Employe'), 'column' => 'id')),
      'observation'             => new sfValidatorPass(array('required' => false)),
      'confirme'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'valider'                 => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'livre'                   => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'cloture'                 => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'foire_id'                => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Foire'), 'column' => 'id')),
      'created_at'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'deleted_at'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'm_stock_article_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle', 'required' => false)),
      'stock_articles_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('bon_sortie_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMStockArticleListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonSortie LigneBonSortie')
      ->andWhereIn('LigneBonSortie.stock_article_id', $values)
    ;
  }

  public function addStockArticlesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonSortie LigneBonSortie')
      ->andWhereIn('LigneBonSortie.stock_article_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'BonSortie';
  }

  public function getFields()
  {
    return array(
      'id'                      => 'Number',
      'reference'               => 'Text',
      'reference_bon_livraison' => 'Text',
      'date_creation'           => 'Date',
      'date_validite'           => 'Date',
      'client_id'               => 'ForeignKey',
      'departement_source_id'   => 'ForeignKey',
      'facture_id'              => 'ForeignKey',
      'bon_livraison_client_id' => 'ForeignKey',
      'magasinie_id'            => 'ForeignKey',
      'observation'             => 'Text',
      'confirme'                => 'Boolean',
      'valider'                 => 'Boolean',
      'livre'                   => 'Boolean',
      'cloture'                 => 'Boolean',
      'foire_id'                => 'ForeignKey',
      'created_at'              => 'Date',
      'updated_at'              => 'Date',
      'deleted_at'              => 'Date',
      'm_stock_article_list'    => 'ManyKey',
      'stock_articles_list'     => 'ManyKey',
    );
  }
}
